package dao

import (
	"family/model"
	"family/pkg/db"
)

var SpouseDao = new(spouseDao)

type spouseDao struct{}

func (*spouseDao) Create(spouse *model.Spouse) error {
	spouse.ID = db.GetId()
	return db.DB.Create(&spouse).Error
}

func (*spouseDao) Page(id uint64) ([]*model.Spouse, int64, error) {
	var spouse []*model.Spouse
	var total int64
	result := db.DB.Where(&model.Spouse{People: id}).Find(&spouse)
	if result.Error != nil {
		return nil, 0, result.Error
	}
	return spouse, total, nil
}

func (*spouseDao) Info(id string) (*model.Spouse, error) {
	var spouse model.Spouse
	err := db.DB.First(&spouse, id).Error
	if err != nil {
		return nil, err
	}
	return &spouse, nil
}

func (*spouseDao) Update(spouse *model.Spouse) error {
	return db.DB.Model(&spouse).Updates(&spouse).Error
}

func (*spouseDao) Delete(ids []string) error {
	var spouse model.Spouse
	return db.DB.Delete(&spouse, ids).Error
}
